package javagprssrv.Listener;

import javagprssrv.JGS_Param;
import javagprssrv.Log;
import java.net.DatagramSocket;

public class TrdJSSJDataListener extends java.lang.Thread
{
    private int SocketIndex;
    private java.lang.String SocketName;
    private java.lang.String SocketProto;
    
    public TrdJSSJDataListener(final java.lang.String _Protocal, final int _SocketIndex, final java.lang.String _SocketName) {
        super("TrdJSSJDataListener");
        this.SocketIndex = -1;
        this.SocketName = "";
        this.SocketProto = "";
        this.SocketProto = _Protocal;
        this.SocketIndex = _SocketIndex;
        this.SocketName = _SocketName;
    }
    
    @java.lang.Override
    public void run() {
        try {
            if (this.SocketProto.equals("TCP")) {
                final javagprssrv.Listener.TrdJSSJDataListener_TCP TJSSJDL_T = new javagprssrv.Listener.TrdJSSJDataListener_TCP(this.SocketProto, this.SocketName, this.SocketIndex);
                TJSSJDL_T.start();
            }
            if (this.SocketProto.equals("UDP")) {
                final int a = 0;
                if (a == 0) {
                    return;
                }
                final java.net.DatagramSocket server = new java.net.DatagramSocket(this.SocketIndex);
                if (server.isBound()) {
                    new javagprssrv.Log().ShowLog(this.SocketName + "(" + this.SocketProto + ":" + java.lang.Integer.valueOf(this.SocketIndex).toString() + ") 打开成功。", true, true);
                    int idx = -1;
                    synchronized (this) {
                        idx = javagprssrv.JGS_Param.UDPServerSockets.size();
                        javagprssrv.JGS_Param.UDPServerSockets.add(server);
                    }
                    final javagprssrv.Listener.TrdYiBiaoDataListener_UDP TYBDL_U = new javagprssrv.Listener.TrdYiBiaoDataListener_UDP(idx);
                    TYBDL_U.start();
                }
                else {
                    new javagprssrv.Log().ShowLog(this.SocketName + "(" + this.SocketProto + ":" + java.lang.Integer.valueOf(this.SocketIndex).toString() + ") 打开失败！", true, true);
                }
            }
        }
        catch (java.lang.Exception e) {
            java.lang.String strERR = "";
            final java.lang.String strLine = java.lang.System.getProperty("line.separator");
            strERR = this.SocketName + "(" + this.SocketProto + ":" + java.lang.Integer.valueOf(this.SocketIndex).toString() + ") 打开失败！" + strLine;
            strERR = strERR + "                    (建议)请使用“netstat -an”命令,查看" + java.lang.Integer.valueOf(this.SocketIndex).toString() + "端口是否已经被使用。";
            javagprssrv.JGS_Param.myLog.ShowLog(strERR, true, true);
        }
    }
}
